using System.ComponentModel;
using System.Diagnostics;
using System.Xml.Serialization;

namespace Edmx.Storage
{
    [DebuggerDisplay("Name={Name}, Type={Type}")]
    [XmlType(Namespace = EdmxConstants.StorageSchemaNamespace)]
    public class Property : MetadataEntityBase<Property>
    {
        public Property()
        {
            Nullable = true;
        }

        [XmlAttribute("Name")]
        public string Name { get; set; }

        [XmlAttribute("Type")]
        public string Type { get; set; }

        [XmlAttribute("Nullable")]
        [DefaultValue(true)]
        public bool Nullable { get; set; }

        [XmlAttribute("DefaultValue")]
        public string DefaultValue { get; set; }

        private int? _maxLength;

        [XmlAttribute("MaxLength")]
        public int MaxLength
        {
            get { return _maxLength ?? 0; }
            set { _maxLength = value; }
        }

        public bool ShouldSerializeMaxLength()
        {
            return _maxLength.HasValue;
        }

        private bool? _fixedLength;

        [XmlAttribute("FixedLength")]
        public bool FixedLength
        {
            get { return _fixedLength ?? false; }
            set { _fixedLength = value; }
        }

        public bool ShouldSerializeFixedLength()
        {
            return _fixedLength.HasValue;
        }

        private int? _precision;

        [XmlAttribute("Precision")]
        public int Precision
        {
            get { return _precision ?? 0; }
            set { _precision = value; }
        }

        public bool ShouldSerializePrecision()
        {
            return _precision.HasValue;
        }

        private int? _scale;

        [XmlAttribute("Scale")]
        public int Scale
        {
            get { return _scale ?? 0; }
            set { _scale = value; }
        }

        public bool ShouldSerializeScale()
        {
            return _scale.HasValue;
        }

        private bool? _unicode;

        [XmlAttribute("Unicode")]
        public bool Unicode
        {
            get { return _unicode ?? false; }
            set { _unicode = value; }
        }

        public bool ShouldSerializeUnicode()
        {
            return _unicode.HasValue;
        }

        [XmlAttribute("Collation")]
        public string Collation { get; set; }

        private StoreGeneratedPattern? _storeGeneratedPattern;

        [XmlAttribute("StoreGeneratedPattern")]
        public StoreGeneratedPattern StoreGeneratedPattern
        {
            get { return _storeGeneratedPattern ?? StoreGeneratedPattern.None; }
            set { _storeGeneratedPattern = value; }
        }

        public bool ShouldSerializeStoreGeneratedPattern()
        {
            return _storeGeneratedPattern.HasValue;
        }
    }
}